<?php
error_reporting(0);
require_once("includes/pagetop.php");

include_once("updates/CommonFeatures.php");
include_once("includes/common_snippets.php");

if(!isset($_SESSION['Allyfolio_User_ID']) || $_SESSION['Allyfolio_User_ID']==0)
{
    redirect("index.php");
}

$patharr=explode("/",$_SERVER["REQUEST_URI"]);

$lastvars=end($patharr);

$afterWampToProjectRootPath=str_replace($lastvars,"",$_SERVER["REQUEST_URI"]);
if(!(isset($_REQUEST['t']) && trim($_REQUEST['t'])!=''))
{
    redirect("home.php");
}

$dnauserqry="select * from af_users where Allyfolio_User_ID=:afuserid  ";
$condition[":afuserid"]=$_REQUEST['t'];
$dnauserinfo=$pdodbobj->fetch_array($pdodbobj->query($dnauserqry,$condition));

if(count($dnauserinfo)==0)
{
    redirect($_SERVER["HTTP_REFERER"]);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<meta http-equiv="X-UA-Compatible" content="IE=edge" />

<title>AllyFolio | DNA </title>

<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />

<script src="js/general.js"></script>

<script src="js/functions.js"></script>

<script type="text/javascript" src="js/jquery-1.8.0.min.js"></script>


<link rel="stylesheet" href="bin/magicsuggest-1.3.1-min.css"/>
<script type="text/javascript" src="bin/jquery-1.8.3-min.js"></script>
<script type="text/javascript" src="bin/magicsuggest-1.3.1-min.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>
<script src="js/modernizr.custom.56223.js"></script>

<script src="js/jquery.placeholder.js"></script>
<!-- For sharing popup -->
<script type="text/javascript" src="js/script.js"></script>

<style type="text/css">

	.logo{ margin-top:10px;}

	.log_button{

	height:auto;

	margin:6px 0;

	overflow:hidden;

	float:left;

	margin-top:10px;

	}

	.new tr td{ vertical-align:top}

	textarea select{ border:1px solid #ccc}

	input textarea select{ border:1px solid #999}

	

</style>

</head>

<body>
	<div id="main_wrapper">

    <!--=================Header Start=======================-->

	<div class="wrapper row1">
    
    <?php
    require_once("includes/dnaheader.php");
    
    $condition=array();
    
    $joinedPages=" select * from af_company_page_members as cpm left join af_company_page as cp on cpm.comp_page_id=cp.Comp_Page_ID where cpm.user_id=:user_id and cp.Comp_Type_ID != 18 and cp.Status=0";
    $condition[":user_id"]=$dnauserinfo[0]['User_ID'];
    $joinedPagesInfo=$pdodbobj->fetch_array($pdodbobj->query($joinedPages,$condition));
    
    ?>
    <div class="clearfix"></div>  

    </div>

    <div class="clearfix"></div>

    <!--=================Header end=======================-->

    <!--=================Body Contain Start=======================-->

    <div class="wrapper">

      <div class="header">

        <?php include_once("dna_top.php"); ?>

 <table width="100%">

 	<tr>

		<td>
			<div class="new_box_heading">

				Picks

			</div>
		<?php
			if(count($joinedPagesInfo)>0)
			{
		?>
			<table width="90%" border="0" class="under_box">
				<tr>
			<?php
				for($i=0;$i<count($joinedPagesInfo);$i++)
				{
					if($i%2==0 && $i!=0)
					{
					?>
						</tr><tr>
					<?php	
					}
			?>
					<td>
						<a href="page.php?page=<?php echo $joinedPagesInfo[$i]['Page_Slug']; ?>">
							<img id="Comp_Page_Pic_img" src="<?php if($joinedPagesInfo[$i]["Comp_Page_Pic"]!="" ){ echo "uploads/image_crop.php?image=/".$joinedPagesInfo[$i]["Comp_Page_Pic"]."&width=50&height=50&cropratio=50:50"; } else { echo "uploads/image_crop.php?image=/images/dummy_image.jpg&width=50&height=50&cropratio=50:50"; } ?>" alt="<?php  echo $joinedPagesInfo[$i]["Comp_Page_Name"]; ?>" />
						</a>
					</td>
					<td>
						<a style="font-style:inherit;color: inherit;" href="page.php?page=<?php echo $joinedPagesInfo[$i]['Page_Slug']; ?>"><?php echo $joinedPagesInfo[$i]['Comp_Page_Name']; ?></a>
						<br>
					<?php
						if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0 && $joinedPagesInfo[$i]["User_ID"]!=$_SESSION['Allyfolio_User_ID'])
						{
							//check current user picked this page or not.
							$qryCheckCurrentPicked="select * from af_company_page_members where comp_page_id=:comp_page_id and user_id:user_id";
							$condition[":user_id"]=$_SESSION['Allyfolio_User_ID'];
							$condition[":comp_page_id"]=$joinedPagesInfo[$i]['Comp_Page_ID'];
		    				$arrCheckCurrentPicked=$pdodbobj->fetch_array($pdodbobj->query($qryCheckCurrentPicked,$condition));
							if(count($arrCheckCurrentPicked)>0)
							{
						?>
								<a href="javascript:void(0)" onclick="return togglePickUnpick('<?php echo $joinedPagesInfo[$i]['Comp_Page_ID']; ?>')"><span id="pick_span_<?php echo $joinedPagesInfo[$i]['Comp_Page_ID']; ?>">Unpick</span></a>
						<?php
							}
							else
							{
						?>
								<a href="javascript:void(0)" onclick="return togglePickUnpick('<?php echo $joinedPagesInfo[$i]['Comp_Page_ID']; ?>')"><span id="pick_span_<?php echo $joinedPagesInfo[$i]['Comp_Page_ID']; ?>">Pick</span></a>
						<?php		
							}
						}	
					?>	
					</td>
				</tr>
			<?php	
				}
			?>
				</tr>
			</table>
		<?php		
			}
			else
			{
				echo "There is no picked pages.";
			}
		?>
		</td>

		<td style="vertical-align: top;">
        <form name="eventform" method="post">
        	<div class="new_box_heading">
				Clusters
			</div>
		<?php
            $oDropfilters= new CGetFilters();
            $clusterDrops=$oDropfilters->getClusters($dnauserinfo[0]['User_ID'],1); 

            foreach($clusterDrops as $mycluster)
			{
                ?>
                <table width="90%" border="0" class="under_box">
    				<tr>
    					<td>
                            <a onclick="showMyClusters('<?php echo $mycluster["Cluster_ID"]; ?>',this.innerHTML);"><?php echo $mycluster["Cluster_Name"]; ?></a>
                        </td>
    				</tr>
    			</table>
                <?php
            }
        ?>
         </form>
		</td>

	</tr>

 </table>
 

       </div>  
       
</div>

    </div>

    

    <div class="clearfix"></div>

    <!--=================Body Contain end=======================-->

    </div>

 <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[

function togglePickUnpick(pageid)
{
	var xmlhttp;
	var ajaxURL="ajax_dna_profile.php?purpose=pick&Comp_Page_ID="+pageid;
	if (window.XMLHttpRequest)
	{// code for IE7+, Firefox, Chrome, Opera, Safari
		xmlhttp=new XMLHttpRequest();
	}
	else
	{// code for IE6, IE5
		xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
	}
	xmlhttp.onreadystatechange=function()
	{
		if (xmlhttp.readyState==4 && xmlhttp.status==200)
		{	
			var res=xmlhttp.responseText;	
			resArr=res.split("|~|");
			if(resArr[0]=="SUCCESS")
			{
				document.getElementById("pick_span_"+pageid).innerHTML=resArr[1]
			}
			else
			{
				alertify.alert(resArr[1]);
			}
		}
	}	
	xmlhttp.open("POST",ajaxURL,true);
	xmlhttp.send();
}

    function viewEventInfo(evtid,flag)
    {
        document.getElementById(['event_id']).value=evtid;
        if(evtid!="")
        {
            if(flag==0)
            {
                document.eventform.action='event_details.php';
                document.getElementById('actiontype').value="";
            }
            else
            {
                document.getElementById('actiontype').value="editeventinfo";    
            }
            
            document.eventform.submit();
        }
    }
    
//]]>
</script>